package com.ruoyi.web.controller.item;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.item.domain.ItemCategory;
import com.ruoyi.item.service.IItemCategoryService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 赛道管理Controller
 * 
 * @author ruoyi
 * @date 2022-03-14
 */
@RestController
@RequestMapping("/item/category")
public class ItemCategoryController extends BaseController
{
    @Autowired
    private IItemCategoryService itemCategoryService;

    /**
     * 查询赛道管理列表
     */
    @PreAuthorize("@ss.hasPermi('item:category:list')")
    @GetMapping("/list")
    public TableDataInfo list(ItemCategory itemCategory)
    {
        startPage();
        List<ItemCategory> list = itemCategoryService.selectItemCategoryList(itemCategory);
        return getDataTable(list);
    }

    /**
     * 导出赛道管理列表
     */
    @PreAuthorize("@ss.hasPermi('item:category:export')")
    @Log(title = "赛道管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ItemCategory itemCategory)
    {
        List<ItemCategory> list = itemCategoryService.selectItemCategoryList(itemCategory);
        ExcelUtil<ItemCategory> util = new ExcelUtil<ItemCategory>(ItemCategory.class);
        util.exportExcel(response, list, "赛道管理数据");
    }

    /**
     * 获取赛道管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('item:category:query')")
    @GetMapping(value = "/{categoryId}")
    public AjaxResult getInfo(@PathVariable("categoryId") Long categoryId)
    {
        return AjaxResult.success(itemCategoryService.selectItemCategoryByCategoryId(categoryId));
    }

    /**
     * 新增赛道管理
     */
    @PreAuthorize("@ss.hasPermi('item:category:add')")
    @Log(title = "赛道管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ItemCategory itemCategory)
    {
        return toAjax(itemCategoryService.insertItemCategory(itemCategory));
    }

    /**
     * 修改赛道管理
     */
    @PreAuthorize("@ss.hasPermi('item:category:edit')")
    @Log(title = "赛道管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ItemCategory itemCategory)
    {
        return toAjax(itemCategoryService.updateItemCategory(itemCategory));
    }

    /**
     * 删除赛道管理
     */
    @PreAuthorize("@ss.hasPermi('item:category:remove')")
    @Log(title = "赛道管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{categoryIds}")
    public AjaxResult remove(@PathVariable Long[] categoryIds)
    {
        return toAjax(itemCategoryService.deleteItemCategoryByCategoryIds(categoryIds));
    }
}
